<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>添加（编辑）商品</title>
<link href="__PUBLIC__/admin/css/xc.min.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/admin/css/xc.admin.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/iconfont/iconfont.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.js"></script> 
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.admin.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/common-1.0.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/WdatePicker.js"></script>
</head>

<body>
<div class="pd-10">
  <form action="" method="post" class="form form-horizontal" id="myform" enctype="multipart/form-data">
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>商品名称：</label>
      <div class="formControls col-8">
        <input type="text" class="input-text" placeholder="请输入商品名称" id="pname" name="pname" value="{$res.gp_name}">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>商品等级：</label>
      <div class="formControls col-8">
         <span class="select-box"><select class="select" id="gid" name="gid">
           <volist name='grFind' id='cvo'>
             <option value="{$cvo.gr_id}" <if condition="($res[gp_gid] eq $cvo[gr_id])">selected</if>>{$cvo.gr_name}</option>
           </volist>
         </select></span>
        <!--<input type="text" class="input-text" placeholder="请输入商品名称" id="gid" name="gid" value="{$grFind.gr_name}">-->
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>市场价：</label>
      <div class="formControls col-8">
        <input type="text" class="input-text" id="money" name="money" placeholder="请输入市场价" value="{$res.gp_money}">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>兑换价：</label>
      <div class="formControls col-8">
        <input type="text" class="input-text" id="price" name="price" placeholder="请输入商品兑换价" value="{$res.gp_price}">
      </div>
    </div>
    <!--<div class="row cl">-->
      <!--<label class="form-label col-3"><span class="c-red">*</span>释放积分：</label>-->
      <!--<div class="formControls col-8">-->
        <!--<input type="text" class="input-text" id="points" name="points" placeholder="请输入释放积分数量" value="{$res.gp_points}">-->
      <!--</div>-->
    <!--</div>-->
    <!--<div class="row cl">-->
      <!--<label class="form-label col-3"><span class="c-red">*</span>上级释放积分：</label>-->
      <!--<div class="formControls col-8">-->
        <!--<input type="text" class="input-text" id="points" name="tj" placeholder="请输入释放积分数量" value="{$res.gp_tj}">-->
      <!--</div>-->
    <!--</div>-->
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>商品缩略图：</label>
      <div class="formControls col-6"><span class="btn-upload form-group">
        <input class="input-text" type="text" id="thumbImgUrl" name="thumbImgUrl" readonly style="width:150px" value="{$res.gp_thumb}" placeholder="请上传兑换商品缩略图" />
        <a href="javascript:;" class="a-upload" onchange="uploadImage('myfile','prop','thumb');"><input type="file" name="myfile" id="myfile" alt="上传文件">点击上传文件</a>
       </span></div>
      <img id="thumbImg" src="__UPLOAD__/{$res.gp_thumb|default='img/no_image.jpg'}" style="width:100px; height:100px; float: left">
    </div>
    <div class="row cl">
      <div class="col-9 col-offset-3">
        <input type="hidden" id="id" name="id" value="{$res.gp_id}">
        <button type="button" id="sub" name="sub" class="btn btn-primary radius" onClick="checkSubmit()"><i class='Hui-iconfont'>&#xe632;</i> 保存</button>
        <input class="btn btn-default radius" type="button" onClick="layer_close();" value="取消"/>
      </div>
    </div>
  </form>
</div>
<script type="text/javascript">
//按回车件触发提交
document.onkeydown=function(event){
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && e.keyCode==13){ // enter 键
		checkSubmit();
	}
}; 
//提交数据
function checkSubmit()
{
	var pname = $.trim($('#pname').val());
	var price = $.trim($('#price').val());
  var money = $.trim($('#money').val());
	var imgurl= $.trim($('#thumbImgUrl').val());
	if(pname == ''){
		layer.msg('兑换商品名称不能为空', {icon: 2});
		return false;
	}if(money == ''){
		layer.msg('市场价不能为空!', {icon: 2});
		return false;
	}if(price == ''){
		layer.msg('兑换价不能为空!', {icon: 2});
	    return false;
	}if(imgurl == ''){
		layer.msg('兑换商品缩略图未上传!', {icon: 2});
		return false;
	}
	$.ajax({
		type : 'post',
		url : "{:U('Goods/propAddEdit')}",
		data : $("#myform").serialize(),
		dataType : 'json',
		success : function(res){
			if(res.status == 1){
				layer.msg(res.msg,{icon:1,time:2000},function(){
					// 先获取窗口索引，才能关闭窗口  
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				});
				parent.call_back_fun('success');
			}else{
				layer.msg(res.msg, {icon: 2});
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			layer.alert('网络失败，请刷新页面后重试',{icon:2});
		}
	})
}
</script>

</body>
</html>